//
//  ForwardStatusCell.swift
//  WeiBoSwift
//
//  Created by Jacky Sun on 16/5/17.
//  Copyright © 2016年 syf. All rights reserved.
//

import UIKit
import SnapKit
import KILabel

class ForwardStatusCell: StatusHomeCell {
    
    override var status: Status?{
        didSet{
            let name = status?.retweeted_status?.user?.name ?? ""
            let text = status?.retweeted_status?.text ?? ""
            let statusText = "@" + name + ": " + text
           forwardLabel.attributedText = EmoticonPackage.returnAttritbute(statusText, font: forwardLabel.font)
            
            let textSize = forwardLabel.adaptLabLineSpacing(3, maxSize:CGSize(width:UIScreen.mainScreen().bounds.size.width-20 , height: CGFloat(MAXFLOAT)) , text: forwardLabel.text!)
            forwardLabel.snp_updateConstraints { (make) in
                make.height.equalTo(textSize.height)
                make.width.equalTo(textSize.width)
            }
        }
    }
    

    override var colltionTop: CGFloat{
        didSet{
            colltionView.snp_updateConstraints { (make) in
                make.left.equalTo(forwardLabel)
                make.width.equalTo(colltionViewSize.width)
                make.height.equalTo(colltionViewSize.height)
                make.top.equalTo(forwardLabel.snp_bottom).offset(colltionTop)
            }
        }
    }
    
    
    override func setUpUI() {
        super.setUpUI()
        contentView.insertSubview(bgBtn, belowSubview: colltionView)
        contentView.insertSubview(forwardLabel, aboveSubview: bgBtn)
        
        bgBtn.snp_makeConstraints { (make) in
            make.left.right.equalTo(contentView)
            make.top.equalTo(contentLabel.snp_bottom).offset(10)
            make.bottom.equalTo(footView.snp_top)
        }
        
        //给正文赋值
        //update constraint
        forwardLabel.snp_makeConstraints { (make) in
            make.height.equalTo(1)
            make.width.equalTo(1)
            make.centerX.equalTo(contentView)
            make.top.equalTo(bgBtn.snp_top).offset(10)
        }
    }
    
     /// 背景的btn
    private lazy var bgBtn: UIButton = {
       let btn = UIButton()
        btn.backgroundColor = UIColor(white: 0.9, alpha: 1.0)
        return btn
    }()
    
    /// 转发正文
    private lazy var forwardLabel: KILabel =
    {
            let label = KILabel()
            label.textColor = UIColor.darkGrayColor()
            label.numberOfLines = 0
            label.font = UIFont.systemFontOfSize(18)
            label.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - 20
            return label
    }()

   
}
